﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CJJCH.Web
{
    public partial class NewsDetail : System.Web.UI.Page
    {
        CJJCH.BLL.T_NET_News bll_news = new CJJCH.BLL.T_NET_News();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitRequest();
                ModelDataBind();
            }
        }

        private void InitRequest()
        {
            if (Request.QueryString["ID"]!=null&&LTP.Common.CheckInput.CheckGUID(Request.QueryString["ID"].ToString()))
            {
                ViewState["ID"] = Request.QueryString["ID"].ToString();
            }
            else
            {
                Response.Redirect("error.aspx");
            }
            if (Request.QueryString["curpage"]!=null&&LTP.Common.CheckInput.CheckDigit(Request.QueryString["curpage"].ToString()))
            {
                this.lblCurpage.Text = Request.QueryString["curpage"].ToString();
            }
            else
            {
                this.lblCurpage.Text = "1";
            }
            if (Request.QueryString["firstid"]!=null&&LTP.Common.CheckInput.CheckDigit(Request.QueryString["firstid"].ToString()))
            {
                this.lblFirstID.Text = Request.QueryString["firstid"].ToString();
            }
            //else
            //{
            //    Response.Redirect("error.aspx");
            //}
            if (Request.QueryString["secondid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["secondid"].ToString()))
            {
                this.lblSecondID.Text = Request.QueryString["secondid"].ToString();
            }
            //else
            //{
            //    Response.Redirect("error.aspx");
            //}
            if (Request.QueryString["thirdid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["thirdid"].ToString()))
            {
                this.lblThirdID.Text = Request.QueryString["thirdid"].ToString();
            }
            //else
            //{
            //    Response.Redirect("error.aspx");
            //}
        }

        private void ModelDataBind()
        {
            bll_news.AddHits(new Guid(ViewState["ID"].ToString()));
            CJJCH.Model.T_NET_News model = new CJJCH.Model.T_NET_News();
            model = bll_news.GetNewsModel(new Guid(ViewState["ID"].ToString()));
            if (model!=null)
            {
                this.top.IIndex = model.FirstID;
                this.Literal1.Text = model.DataTitle;
                this.lblHits.Text = model.Hits.ToString();
                this.lblDataSource.Text = model.DataSource;
                this.lblPlusDate.Text = model.PlusDate.ToString("yyyy年MM月dd日");
                this.lblTitle.Text = model.DataTitle;
                this.divDataNote.InnerHtml = Server.HtmlDecode(model.DataNote);
                this.lblTitle1.Text = model.DataTitle;

                    switch (model.FirstID)
                    {
                        case 0:
                            this.lnkFirst.Text = "首 页";
                            this.lnkFirst.NavigateUrl = "../Index.aspx";
                            break;
                        case 1:
                            this.lnkFirst.Text = "新闻动态";
                            this.lnkFirst.NavigateUrl = "../ListPage.aspx?firstid=1&IIndex=2";
                            break;
                        case 2:
                            this.lnkFirst.Text = "技术标准";
                            this.lnkFirst.NavigateUrl = "../ListPage.aspx?firstid=2&IIndex=3";
                            break;
                        case 3:
                            this.lnkFirst.Text = "教育培训";
                            this.lnkFirst.NavigateUrl = "../ListPage.aspx?firstid=3&IIndex=4";
                            break;
                        case 4:
                            this.lnkFirst.Text = "专家评审";
                            this.lnkFirst.NavigateUrl = "";
                            break;
                        case 5:
                            this.lnkFirst.Text = "科技推广";
                            this.lnkFirst.NavigateUrl = "../ListPage.aspx?firstid=5&IIndex=6";
                            break;
                        case 6:
                            this.lnkFirst.Text = "协会刊物";
                            this.lnkFirst.NavigateUrl = "../NotePage.aspx?firstid=6&IIndex=7";
                            break;
                        case 7:
                            this.lnkFirst.Text = "下载中心";
                            this.lnkFirst.NavigateUrl = "../ListPage.aspx?firstid=7&IIndex=8";
                            break;
                        case 8:
                            this.lnkFirst.Text = "关于我们";
                            this.lnkFirst.NavigateUrl = "../NotePage.aspx?firstid=8&IIndex=9";
                            break;
                        default:
                            break;
                    }
                
                if (this.lblThirdID .Text =="0")
                {
                    this.lnkLast.Text = model.MenuSecond.MenuName;
                }
                else
                {
                    this.lnkLast.Text = model.MenuThird.MenuName;
                }
                this.lnkLast.NavigateUrl = "ListPage.aspx?curpage=" 
                    + LTP.Common.StringClass.EncodeUrl(this.lblCurpage.Text.Trim())
                    +"&firstid=" + LTP.Common.StringClass.EncodeUrl(model.FirstID.ToString())
                    +"&secondid="+LTP.Common.StringClass.EncodeUrl(model.SecondID.ToString())
                    + "&thirdid=" + LTP.Common.StringClass.EncodeUrl(model.ThirdID.ToString());
            }
            else
            {
                LTP.Common.WindowClass.WindowBack("操作错误！");
            }
        }
    }
}